<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    
    <form id="DataForm" action="" method="POST" class="layui-form layui-form-pane">
        <div class="layui-tab layui-tab-brief" lay-filter="itemTab">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">

                    <div class="layui-form-item">
                        <label class="layui-form-label">版本</label>
                        <div class="layui-input-block">
                            <select name="info[type]" id="type" lay-search="商家端">
                            <option value="0" id="type_0">直接选择或搜索选择</option>
                            {foreach $type_arr as $key=>$vo}
                                <option value="{$key}" id="type_{$key}">{$vo}</option>
                            {/foreach}
                        </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[title]" placeholder="请输入标题" autocomplete="off"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">应用</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[url]" id="url" value="" autocomplete="off"
                                class="layui-input layui-col-xs6" readonly>
                            <div class="layuimini-upload-btn">
                                <button type="button" class="layui-btn" id="upload_url"><i
                                        class="fa fa-upload"></i>
                                    上传应用</button>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <!-- <input type="number" name="info[content]" placeholder="请输入排序" autocomplete="off"
                                class="layui-input" value="0"> -->
                                <div class="layui-form-item" id="content">
                                   
                                </div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">版本</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[version]" id="version" placeholder="请输入版本" autocomplete="off"
                                class="layui-input" value="0">
                        </div>
                    </div>
                 
                  
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:auto;text-align: center;">
                            <input type="hidden" name="info[package_name]" id="package_name" value="">
                            <input type="hidden" name="info[package_version]" id="package_version" value="">
                            <input type="hidden" name="info[size]" id="size" value="">
                            <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i>
                                提交</button>
                            <button id="closeButton" type="button" class="layui-btn layui-btn-primary"><i
                                    class="fa fa-close"></i>
                                关闭</button>
                        </div>
                    </div>
                </div>

              

            </div>
        </div>
    </form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
      layui.use(['layer', 'form', 'laydate', 'element', 'upload','wangEditor'], function () {

        var $ = layui.$, layer = layui.layer, table = layui.table,  element = layui.element,laydate = layui.laydate, form = layui.form, upload = layui.upload;
        var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $("#saveButton").on('click', function () {
            var loading = layer.open({ type: 3 });
            console.log(content.txt.html());
            $.ajax({
                url: "{:url('add')}",
                type: 'post',
                data: $("#DataForm").serialize()+"&info[content]="+content.txt.html(),
                success: function (data) {
                    console.log(data);
                    layer.close(loading);
                    if (data.code == 0) {
                        parent.tableReload();
                        parent.layer.close(indexFrame);
                        parent.layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
            return false;
        })

        $("#closeButton").on('click', function () {
            parent.layer.close(indexFrame);
        })

        // 分步表单下一步
        $(".downButton").on('click', function () {
            var id = $(".layui-this").next().attr('lay-id');
            element.tabChange('itemTab', id);
        });
        // 分步表单上一步
        $(".upButton").on('click', function () {
            var id = $(".layui-this").prev().attr('lay-id');
            element.tabChange('itemTab', id);
        });

        upload.render({
                elem: '#upload_url',
                exts:"apk",
                url: "{:url('apk')}", 
                done: function (res) {
                        $("#url").val(res.data.url);
                        $("#version").val(res.data.package_version);
                        $("#type_"+res.data.type).attr("selected",true);
                   
                        $("#package_name").val(res.data.package_name);
                        $("#package_version").val(res.data.package_version);
                        $("#size").val(res.data.size);
                        form.render('select')
                        layer.msg(res.msg);
                }
        });
        var wangEditor = layui.wangEditor;
        var content = new wangEditor('#content');
        content.customConfig.pasteFilterStyle = false;
        content.customConfig.uploadImgMaxLength = 5;
        content.customConfig.menus = [
            'head',  // 标题
            'bold',  // 粗体
            'fontSize',  // 字号
            'fontName',  // 字体
            'italic',  // 斜体
            'underline',  // 下划线
            'strikeThrough',  // 删除线
            'foreColor',  // 文字颜色
            'backColor',  // 背景颜色
            'link',  // 插入链接
            'list',  // 列表
            'justify',  // 对齐方式
            'table',  // 表格
            'undo',  // 撤销
            'redo'  // 重复
        ];
        content.create();
       

        });
</script>
</body>
</html>